/*
 * @Author: Clark
 * @Email: haixuanwoTxh@gmail.com
 * @Date: 2023-01-10 08:37:13
 * @LastEditors: Clark
 * @LastEditTime: 2023-01-10 08:46:26
 * @Description: file content
 */

#include "apue.h"

unsigned int sleep2(unsigned int);
static void sig_int(int);

int main(void)
{
    unsigned int uslept;

    if (signal(SIGINT, sig_int) == SIG_ERR)
    {
        err_sys("signal(SIGINT) error");
    }

    uslept = sleep2(5);
    printf("sleep2 returned: %u\n", uslept);
    exit(0);
}

static void sig_int(int signo)
{
    volatile int k;

    printf("\nsig_int starting\n");

    for (int i = 0; i < 300000; i++)
    {
        for (int j = 0; j < 4000; j++)
        {
            k += i*j;
        }
    }

    printf("sig_int finished\n");
}
